package com.example.shiwu.service;

import com.example.shiwu.db.dao.ArrangeDao;
import com.example.shiwu.db.dao.base.BaseDaoFactory;
import com.example.shiwu.db.model.Arrange;
import com.example.shiwu.manager.DatabaseHelper;

import java.util.ArrayList;
import java.util.List;

public class ArrangeService {

    private DatabaseHelper dbHelper;
    private ArrangeDao<Arrange> ArrangeDao;
    private ArrayList<Arrange> listArrange = new ArrayList<>();

    private static final int PAGE_SIZE = 10;
    private static final int TOTAL_PAGE = 0;



    /**获取单个数据
     * @param arrange
     * @return
     */
    public List<Arrange> getArrange(Arrange arrange) {
        listArrange = new ArrayList<>();
        ArrangeDao = BaseDaoFactory.getInstance().createBaseDao(ArrangeDao.class, Arrange.class);
        listArrange.addAll(ArrangeDao.query(arrange));
        return listArrange;
    }

    /**分页获取数据
     * @param arrange
     * @return
     */
    public List<Arrange> getArrangeList(Arrange arrange,Integer startIndex,Integer limit) {
        ArrangeDao = BaseDaoFactory.getInstance().createBaseDao(ArrangeDao.class, Arrange.class);
        listArrange = new ArrayList<>();
        listArrange.addAll(ArrangeDao.query(arrange,null,"create_time desc",null,startIndex,limit));
        return listArrange;
    }

    public boolean save(Arrange arrange) {
        ArrangeDao = BaseDaoFactory.getInstance().createBaseDao(ArrangeDao.class, Arrange.class);
        long size = ArrangeDao.insert(arrange);
        if(size >0 ){
            return true;
        }
        return false;
    }

    public boolean updade(Arrange arrange,Arrange where) {
        ArrangeDao = BaseDaoFactory.getInstance().createBaseDao(ArrangeDao.class, Arrange.class);

        long size = ArrangeDao.update(arrange,where);
        if(size >0 ){
            return true;
        }
        return false;
    }
}
